package com.hbisdt.cet.sample.config;

import com.hbisdt.cet.sample.config.intercepter.AuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description
 * @Author Jiam
 * @Date 2025-10-08 1:55
 */
@Configuration
public class SpringMvcConfiguration implements WebMvcConfigurer {
    @Autowired
    private AuthInterceptor authInterceptor;

    /**
     * 配置路由规则
     *
     * @param registry
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("redirect:/view/login");
        registry.addViewController("/toLogin").setViewName("redirect:/view/login");
        registry.addViewController("/index").setViewName("redirect:/view/login");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/login", "/view/login", "/toLogin", "/index", "/static/**", "/js/**", "/css/**");
    }
}
